<template>
  <div class="container">
    <!-- 布局容器 -->
    <el-container>
      <!-- 头部区域 -->
      <el-header>
        <el-row class="header">
          <span>水稻病虫害监测与预警系统</span>
          <el-button type="info" @click="out()" size="small" style="float: right;top:50%;transform: translateY(50%);margin-right: 10px">退出</el-button>
        </el-row>
      </el-header>
      <el-container>
        <!-- 侧边栏区域 -->
        <el-aside width="25%" v-if="showaside">
          <div class="nav">
            <el-menu
              unique-opened
              ref="menu"
              active-text-color="#409EFF"
              router
              @select="handleroute"
              :default-active="activePath"
            >
              <el-menu-item index="index">
                <i class="el-icon-s-home"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-finished"></i>
                  <span>任务</span>
                </template>
                <el-menu-item-group>
                  <template slot="title"></template>
                  <el-menu-item index="training-task">新建训练任务</el-menu-item>
                  <el-menu-item index="test-task">新建测试任务</el-menu-item>
                  <el-menu-item index="report-task">新建报表任务</el-menu-item>
                  <el-menu-item index="task-group">新建任务组</el-menu-item>
                  <el-menu-item index="training-record"
                    >训练任务记录</el-menu-item
                  >
                  <el-menu-item index="test-record">测试任务记录</el-menu-item>
                  <el-menu-item index="report-record"
                    >报表任务记录</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="3">
                <template slot="title">
                  <i class="el-icon-collection"></i>
                  <span>数据集</span>
                </template>
                <el-menu-item-group>
                  <template slot="title"></template>
                  <el-menu-item index="data-upload">上传数据集</el-menu-item>
                  <el-menu-item index="data-control">数据集管理</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="4">
                <template slot="title">
                  <i class="el-icon-magic-stick"></i>
                  <span>模型</span>
                </template>
                <el-menu-item-group>
                  <template slot="title"></template>
                  <el-menu-item index="model-upload">新建模型</el-menu-item>
                  <el-menu-item index="model-control">模型管理</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </div>
        </el-aside>
        <!-- 页面主体区域 -->
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { baseUrls } from "@/main.js";
export default {
  data() {
    return {
      // 菜单栏控制
      showaside: true,
      toggleNav: true,
      // 标题栏弹窗
      togeleserchTc: false,
      showserchTc: false,
      shownewsTc: false,
      showuserTc: false,
      // 刷新界面
      fullscreenLoading: false,
      activePath: "",
      token: {
        token: "",
      },
    };
  },
  methods: {
    //导航栏
    handleroute() {
      sessionStorage.setItem("navsession", this.$refs.menu.openedMenus[0]);
    },

    //退出功能
    async out() {
      const { data: res } = await this.$http.get(
        `${baseUrls.base1}/center/logout/?token=${this.token.token}`
      );
      window.sessionStorage.clear("token");
      this.$message.success("退出成功");
      this.$router.push("/login");
    },
    saveNavstate(activePath) {
      // 保存链接的激活状态
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
  //生命周期函数
  created() {
    this.token.token = window.sessionStorage.getItem("token");
    this.activePath = window.sessionStorage.getItem("activePath");
    // console.log(this.token.token);
  },
  mounted() {
    if (sessionStorage.getItem("navsession")) {
      this.$refs.menu.open(sessionStorage.getItem("navsession"));
    }
  },
};
</script>
<style  scoped>
/* 头部区域样式 */
.el-header {
  padding: 0 10px;
  margin-bottom: 10px;
  margin-top: 10px;
}
/* 菜单栏样式 */
.el-aside {
  background-color: #f3f4f7;
  padding: 5px;
  height: 100%;
}
.el-main {
  background-color: #fff;
  border-radius: 10px;
  margin-top: 5px;
  margin-right: 10px;
  height: 92%;
}
.nav {
  width: 95%;
  height: 98%;
  margin: 0px auto;
  border-radius: 10px;
  overflow: hidden;
}
.el-menu {
  height: 95%;
  margin-bottom: 100px;
}
/* 头部样式 */
.header {
  background-color: #fff;
  height: 60px;
  line-height: 60px;
  width: 100%;
  border-radius: 10px;
  justify-content: space-between;
  text-align: center;
}

</style>
